package com.vpen.server.one.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.messaging.simp.annotation.SubscribeMapping;
import org.springframework.stereotype.Controller;

import javax.annotation.Resource;

/**
 * 描述
 *
 * @author 韦鹏
 * @date 2022/11/28 22:38
 */
@Slf4j
@Controller
public class ChatController {

    @Resource
    private SimpMessagingTemplate template;

    @MessageMapping("game")
    @SendTo("/topic/game")
    public String game(@Payload String msg) {
        log.debug("游戏收到消息:{}", msg);
        return "来自游戏：" + msg;
    }


    @MessageMapping("music")
    public void music(@Payload String msg) {
        log.debug("音乐收到消息:{}", msg);
        template.convertAndSend("/topic/music", msg);
    }

    @SubscribeMapping("game-subscribe")
    public String subscribe(@Payload String chatMessage) {
        log.debug("收到消息：{}", chatMessage);
        return "Server:" + chatMessage;
    }


}
